/**
 * Filename: PopSetAvatar.java
 * @author  Firefly
 * @contact postfirefly@163.com
 * @time    2016/3/18 15:08
 */
package com.github.postsanf.yinian.activity.pop;


import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

import com.github.postsanf.yinian.R;

/**
 * 修改头像弹框
 */
public class PopSetTimeMarksBg extends PopupWindow {
	public Button btn_take_photo, btn_pick_photo, btn_cancel;
	public View mMenuView;

	public PopSetTimeMarksBg(Activity context, OnClickListener itemsOnClick, View.OnTouchListener itemsOnTouch) {
		super(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.pop_set_time_marks_bg, null);
		btn_take_photo = (Button) mMenuView.findViewById(R.id.btn_setuser_take_photo);
		btn_pick_photo = (Button) mMenuView.findViewById(R.id.btn_setuser_pick_photo);
		btn_cancel = (Button) mMenuView.findViewById(R.id.btn_setuser_cancel_photo);
		//取消按钮
		btn_cancel.setOnClickListener(itemsOnClick);
		//设置按钮监听
		btn_pick_photo.setOnClickListener(itemsOnClick);
		btn_take_photo.setOnClickListener(itemsOnClick);
		//设置PopSetAvatar的View
		this.setContentView(mMenuView);
		//设置PopSetAvatar弹出窗体的宽
		this.setWidth(LayoutParams.FILL_PARENT);
		//设置PopSetAvatar弹出窗体的高
		this.setHeight(LayoutParams.MATCH_PARENT);
		//设置PopSetAvatar弹出窗体可点击
		this.setFocusable(true);
		//设置PopSetAvatar弹出窗体动画效果
		this.setAnimationStyle(R.style.AnimBottom);
		//实例化一个ColorDrawable颜色为半透明
		ColorDrawable dw = new ColorDrawable(0x00000000);
		//设置PopSetAvatar弹出窗体的背景
		this.setBackgroundDrawable(dw);
		//mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
//		mMenuView.setOnTouchListener(new View.OnTouchListener() {
//			public boolean onTouch(View v, MotionEvent event) {
//				int height = mMenuView.findViewById(R.id.pop_setuser_advatar_layout).getTop();
//				int y=(int) event.getY();
//				if(event.getAction()==MotionEvent.ACTION_UP){
//					if(y<height){
//						dismiss();
//					}
//				}
//				return true;
//			}
//		});
		mMenuView.setOnTouchListener(itemsOnTouch);
	}

}
